<template>
	<view>
		<view class="loadingStyle flexCenterCenter" v-if='vanLoading'>
			<van-loading type="spinner" />
		</view>
		<view class="" v-else>
			<web-view :src="src" v-if="show"></web-view>
		</view>
<!-- {{err}} -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				src: '', // PDF文件地址
				show: true, // 用于判断操作系统
				vanLoading: true,
				err:''
			};
		},

		onLoad(option) {
			// this.vanLoading = true
			// setTimeout(() => {
			// 	this.vanLoading = false

			// }, 2000)
			// this.src = option.src
			this.src =  option.src.replace('https://fbzh-wage.oss-cn-hangzhou.aliyuncs.com', 'https://wage-oss.zhinengjianshe.com');
			const src = `${this.src}`;
			// 判断操作系统
			uni.getSystemInfo({
				success: (res) => {
					if (res.platform == "ios") {
						// iOS 可直接查看
						this.vanLoading = false
						this.show = true;
						this.src = src;
						// uni.navigateTo({
						// 	url: '../home/home'
						// });
					} else {
						// Android 需要下载后、打开
						this.show = false;
						console.log(src);
						uni.downloadFile({
							url: src,
							success: (res) => {
								const path = res.tempFilePath;
								uni.openDocument({
									filePath: path,
									fileType: 'pdf',
									success: (res) => {
										console.log("打开成功！");
										this.vanLoading = false
										// uni.navigateTo({
										// 	url: '../home/home'
										// });
									},
									fail: (err) => {
										uni.showToast({
											title: '打开文件失败',
											icon: 'none',
											duration: 2000
										});
									}
								});
							},
							fail: (err) => {
								console.log(err);
								this.err=err
								uni.showToast({
									title: '下载文件失败',
									icon: 'none',
									duration: 2000
								});
							}
						});
					}
				}
			});
		}
	}
</script>
<style scoped>
	.loadingStyle {
		width: 100%;
		height: 100vh;
	}
</style>
